﻿Public Class perConfiguracoes
    Inherits perPadrao

#Region "Variáveis"

#End Region

#Region "Métodos"
    Public Function BuscarConfiguracoes(ByVal Campo As String) As DataRow
        Dim dsDados As New DataSet
        Dim sSql As String
        Try
            sSql = "SELECT "
            If (Campo <> String.Empty) Then
                sSql &= Campo & vbCrLf
            Else
                sSql &= "*" & vbCrLf
            End If
            sSql &= "FROM DC_Configuracoes "

            dsDados = MyBase.executarConsulta(sSql, "DC_Configuracoes")

            If Not dsDados Is Nothing AndAlso dsDados.Tables("DC_Configuracoes").Rows.Count > 0 Then
                Return dsDados.Tables("DC_Configuracoes").Rows(0)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Throw New Exception("Exceção no método 'BuscarConfiguracoes'. " & Environment.NewLine & Environment.NewLine & ex.Message)
        End Try

    End Function
    Public Function GravarConfiguracoes(ByVal iValor As Integer, ByVal sCampo As String) As Boolean
        Dim bRetorno As Boolean
        Dim sSql As String

        Try
            bRetorno = True

            sSql = "UPDATE DC_Configuracoes " & vbCrLf
            sSql &= "  SET " & sCampo & " = " & iValor

            MyBase.executarAcao(sSql)

        Catch ex As Exception
            bRetorno = False
            Throw New Exception("Exceção no método 'GravarConfiguracoes'. " & Environment.NewLine & Environment.NewLine & ex.Message)
        End Try

        Return bRetorno

    End Function
    Public Function VersaoAtual() As Long
        Dim drResultado As DataRow

        Try
            drResultado = BuscarConfiguracoes("Versao")

            If (Not drResultado Is Nothing) Then

                Return perConversao.nuloParaZero(drResultado.Item("Versao"))

            End If

        Catch ex As Exception

            Return 0
            Throw New Exception("Exceção no método 'VersaoAtual'." & Environment.NewLine & Environment.NewLine & ex.Message)

        End Try

    End Function
#End Region
End Class
